export const handleSplitter = (value:string, splitter: string = "/")=>{
    if (value&&value.slice(-1)===splitter){
        value = value.slice(0, -1);
    }
    return value;
}

export function isHttpLink(url:string) {
    const regex = /^(http:\/\/|https:\/\/|\/\/){0,1}[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/i;
    return regex.test(url);
}

export const randomString = (length: number = 4, chars: string = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') => {
    let result = ''
    for (let i = length; i > 0; --i) {
        result += chars[Math.floor(Math.random() * chars.length)]
    }
    return result
}


export function getURLParamsAsObject(url: string) {
    const urlParams = new URLSearchParams(url);
    let params: Record<string, any> = {};

    for (const [key, value] of urlParams.entries()) {
        params[key] = value;
    }
    return params;
}
